home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / fortran.zip / Q20.FOR < prev    next >
Text File  |  1991-01-10  |  808b  |  44 lines

  1.     integer low/0/
  2.     integer high/10000/
  3.     character ans,inbuf
  4.     write(*,10) high
  5. 10  format(/,'Think of a number in the range 1-',i5,/)
  6.     guess=high/2
  7.  
  8. quiz
  9.     write(*,12) guess
  10. 12  format 'is your number larger than ',i5,' ?  ',$
  11.     wait   ; next character from keyboard
  12.     ans=al
  13.     show_char
  14.     write(*,*) ''  ; return
  15.  
  16.     if(ans.eq.'y') then
  17.     low = guess
  18.     ax=high-low
  19.     shift ax
  20.     if(ax.eq.0) then
  21.     inc  guess
  22.     write(*,23) guess
  23. 23  format('your number is',i6)
  24.     stop
  25.     endif
  26.     add  ax,low
  27.     guess=ax
  28.  
  29.     else
  30.     if(ans.ne.'n') stop
  31.     high=guess
  32.     ax=ax-low
  33.     shift ax
  34.     if(ax.eq.0) then
  35.     write(*,23) guess
  36.     stop|    endif
  37.  
  38. +   mov  bx,high
  39. +   sub  bx,ax
  40. +   mov  guess,bx
  41.     endif
  42.     goto quiz
  43.     end
  44.